<?php

namespace App\Http\Controllers\Admin\Report;

use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;    //引用http请求类
use App\Response\Response;

class UserReportController extends BaseController {

    /**
     * @api {delete} /report/user 用户举报删除
     * @apiVersion 0.1.0
     * @apiName 举报管理-用户举报删除
     * @apiGroup 举报管理
     *
     * @apiParam {string} ids                       字符串分割的id 必传
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     * @apiError 10001 参数校验失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 10001,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function del(Request $request) {
        //参数校验
        try {
            $this->validate($request, [
                'ids' => 'required|string',
            ]);

        } catch (\Exception $e) {
            throw new BasicException(10001, json_encode($e->errors()));
        }

        $idsStr = $request->input("ids");
        $idsArr = explode("," , $idsStr);

        $rows = app('repo_report')->delUserReport($idsArr);
        if (!$rows) {
            throw new BasicException(10001, "删除失败！");
        }

        return Response::sendData(true);
    }


    /**
     * @api {get} /report/user 用户举报列表
     * @apiVersion 0.1.0
     * @apiName 举报管理-用户举报列表
     * @apiGroup 举报管理
     *
     * @apiParam {number} page 当前页数 可选
     * @apiParam {number} perPage 分页容量 可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *
    {
    "code": 200,
    "data": {
        "list": [
            {
                "id": 656,
                "remark(举报理由)": "know",
                "picture(举报图片)": "https://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/img/74936acd79c355798386cab91b98b15b.jpg",
                "add_time(举报时间)": "2020-09-01",
                "user_data": {
                    "user_code(举报人id)": 929123,
                    "head_picture(举报人头像)": "https://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/ios_images/2020-09-28/1FF5168D-4C68-49A0-8DB2-96DEC3E501AD.jpeg"
                },
                "report_user_data": {
                    "user_code(被举报人id)": 929123,
                    "head_picture被举报人头像)": "https://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/img/bb0b3968510ae44455b03dcf5963b93c.jpg"
                }
            }
        ],
        "meta": {
                "page": 1,
                "limit": 10,
                "next": null,
                "total": 1
            }
        }
     }
     *
     *
     */
    public function list(Request $request) {
        //参数校验
        try {
            $this->validate($request, [
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]);
        } catch (\Exception $e) {
            throw new BasicException(10001, json_encode($e->errors()));
        }

        $list = app('repo_report')->getUserReportQueryList($request->input());

        return Response::sendList($list);
    }


}
